package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.UserMark;
import com.hs.sfzy.service.UserMarkService;
import com.hs.sfzy.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName UserMarkController
 * @Description TODO
 * @Author QinKunPeng
 * @Date 2024年10月25日 16:02
 * @Version 1.0
 */
@RestController
@RequestMapping("/userMark")
public class UserMarkController {

    @Autowired
    UserMarkService userMarkService;

    /**
     * 根据id删除用户评价
     *
     * @param id
     * @return java.lang.Object
     * @author QinKunPeng
     * @date 2024/10/25 16:04
     */
    @DeleteMapping("/{id}")
    public Object deleteUserMark(@PathVariable("id") long id) {
        int num = userMarkService.deleteUserMark(id);
        if (num > 0) {
            return ResultUtil.success("删除成功");
        } else {
            return ResultUtil.fail("删除失败");
        }
    }

    /**
     * 新增用户评价【小程序端】
     *
     * @param userMark
     * @return java.lang.Object
     * @author QinKunPeng
     * @date 2024/10/25 16:06
     */
    @PostMapping
    public Object addUserMark(@RequestBody UserMark userMark) {
        if (userMark == null) {
            return ResultUtil.fail("数据异常");
        } else {
            int num = userMarkService.addUserMark(userMark);
            if (num > 0) {
                return ResultUtil.success("添加成功");
            } else {
                return ResultUtil.fail("添加失败");
            }
        }
    }

    /**
     * 动态条件查询用户评价
     *
     * @param userMark
     * @return java.lang.Object
     * @author QinKunPeng
     * @date 2024/10/25 16:08
     */
    @GetMapping
    public Object getUserMarkList(UserMark userMark) {
        List<UserMark> userMarkList = userMarkService.getUserMarkList(userMark);
        return ResultUtil.success("查询成功").setData(userMarkList);
    }

    /**
     * 根据动态条件分页查询用户评价
     *
     * @param userMark
     * @param pageNum
     * @param pageSize
     * @return java.lang.Object
     * @author QinKunPeng
     * @date 2024/10/25 16:10
     */
    @GetMapping("/page")
    public Object getUserMarkListByPage(UserMark userMark,
                                        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                        @RequestParam(value = "pageSize", defaultValue = "5") int pageSize) {
        PageInfo<UserMark> userMarkListByPage =
                userMarkService.getUserMarkListByPage(userMark, pageNum, pageSize);
        return ResultUtil.success("查询成功").setData(userMarkListByPage);
    }

    /**
     * 根据id查询用户评价
     * @author QinKunPeng
     * @date 2024/10/25 16:13
     * @param id
     * @return java.lang.Object
     */
    @GetMapping("/{id}")
    public Object getUserMarkById(@PathVariable("id") long id) {
        UserMark userMark = userMarkService.getUserMarkById(id);
        return ResultUtil.success("查询成功").setData(userMark);
    }

//    @DeleteMapping("/appointment/{id}")
//    public Object deleteByAppId(@PathVariable("id") long id) {
//        int num = userMarkService.deleteByAppId(id);
//        if (num > 0) {
//            return ResultUtil.success("删除成功");
//        }
//
//    }
}
